package com.hotel.config;

import com.hotel.controller.LoginController;
import com.hotel.interceptor.LoginInterceptor;
import com.hotel.interceptor.RememberMeInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
@Configuration
public class ApplicationConfig extends WebMvcConfigurationSupport{
    @Autowired
    private RememberMeInterceptor rememberMeInterceptor;
    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        //拦截所有请求，除了登录页面和接口
        //拦截器
        registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**").excludePathPatterns("/", "/login", "/captcha/**", "/static/**", "/favicon.ico", "/email");
        //拦截器，只拦截登录页面和登录接口
        registry.addInterceptor(rememberMeInterceptor).addPathPatterns("/", "/login");
    }

    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
    }
}
